package com.gxa.web_admin.controller.propertycontroller;


import com.gxa.common.R;
import com.gxa.modules.pojo.Visitor;
import com.gxa.modules.service.propertyservice.VisitorRegisterService;
import io.swagger.annotations.*;
import io.swagger.models.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;


/**
 * @xj
 */
@RestController
@RequestMapping("/VisitorRegister")
@Api(value = "访客管理",tags = "访客信息登记接口API")

public class VisitorRegisterController {

    @Autowired(required = false)
    public R r;
    @Autowired(required = false)
    VisitorRegisterService propertyservice;

    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 400, message = "参数格式不对"),
            @ApiResponse(code = 404, message = "找不到页面"),
            @ApiResponse(code = 500, message = "后台服务错误")
    })
    @RequestMapping(value = "/selectAllVisitorRegisterForPage", method = RequestMethod.GET)
    @ApiOperation(value = "访客信息查询接口", notes = "提供当前页码数与每页显示条数", httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页显示条数", required = true, dataType = "int", paramType = "query")
    })
    public R selectAllVisitorRegisterForPage(int page, int size) {

        return propertyservice.selectAllVisitorRegisterForPage(page, size);
    }

    @RequestMapping(value = "/selectAllVisitorRegister", method = RequestMethod.GET)
    @ApiOperation(value = "根据多种条件查询访客信息接口", notes = "条件查询访客信息", httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页显示条数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "visitorName", value = "访客姓名", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "visitType", value = "访客类型", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "手机", required = false, dataType = "String", paramType = "query")
    })

    public R selectAllVisitorRegister(int page,int size, String visitorName, String visitType,
                                      String phone) {

        return  propertyservice.selectAllVisitorRegister(page,size,visitorName, visitType, phone);

    }


    //    @RequestMapping(value = "/insertVisitorRegister" , method = RequestMethod.POST)
    @PostMapping("/insertVisitorRegister")
    @ApiOperation(value = "添加访客接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R insertVisitorRegister(@RequestBody Visitor visitor)
    {
        return propertyservice.insertVisitorRegister(visitor);
    }


    /**
     * 删除
     * @return 返回删除成功
     */
    @PostMapping("/deleteVisitorRegisterById")
    @ApiOperation(value = "删除访客接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件删除访客信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R deleteVisitorRegisterById(String id)
    {

        return propertyservice.deleteVisitorRegisterById(id);
    }


    /**
     * 根据图片id批量删除图片
     * @param
     */
    @PostMapping("/deleteVisitorRegister")
    @ApiOperation(value = "批量删除访客接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gpId",value = "根据此条件删除访客信息",required = true,dataType = "String",paramType = "query"),
    })
    public void deleteVisitorRegister(@RequestParam(value = "gpId") String gpId) {
        String[] gpIds = gpId.split(",");
        List<Integer> list = new ArrayList<>();
        for(String str:gpIds){
            list.add(Integer.parseInt(str));
        }

        propertyservice.deleteVisitorRegister(list);
    }

    @RequestMapping(value = "/selectDetails", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询访客信息接口", notes = "条件查询访客信息", httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件查询访客信息",required = true,dataType = "String",paramType = "query"),
    })

    public R selectDetails(int id) {

        return  propertyservice.selectDetails(id);

    }




    @RequestMapping(value = "/selectAllVisitorRecordForPage", method = RequestMethod.GET)
    @ApiOperation(value = "显示访客进出记录表", notes = "提供当前页码数与每页显示条数", httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页显示条数", required = true, dataType = "int", paramType = "query")
    })
    public R selectAllVisitorRecordForPage(int page, int size) {

        return propertyservice.selectAllVisitorRecordForPage(page, size);
    }


    @RequestMapping(value = "/selectAllVisitorRecord", method = RequestMethod.GET)
    @ApiOperation(value = "显示访客进出记录表", notes = "条件查询访客信息", httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页显示条数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "visitorName", value = "访客姓名", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "手机", required = false, dataType = "String", paramType = "query")
    })

    public R selectAllVisitorRecord(int page,int size, String visitorName,
                                    String phone) {

        return  propertyservice.selectAllVisitorRecord(page,size,visitorName, phone);

    }

    @PostMapping("/deleteVisitorRecordById")
    @ApiOperation(value = "删除访客接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件删除访客信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R deleteVisitorRecordById(String id)
    {

        return propertyservice.deleteVisitorRecordById(id);
    }




}
